<?php
namespace Admin\Controller;
use Think\Controller;
class CatController extends Controller {
    public function cateadd(){
    	$cat = D("Cat");
    	if(IS_POAT){
    		$data=I("post.");
    		$catid=$cat->add($data);
    		if($catid){
    			$this->redirect("admin/cat/catelist");
    	    }
    	}
    	$this->assign("catArr",$cat->select());
        $this->display();
    }
    public function catelist(){
    	$cat = D("Cat");
        //获取缓存
        $tree = S('tree');
        if(!$tree){
            echo 1;
           $tree=$cat->gettree();
           //缓存5秒
          // S('tree',$tree,5);  
        }
         // S('tree',$null);
    	$this->assign("catArr",$tree);
        $this->display();
    }
    public function cateedit()
    {
    	$cat = D("Cat");
    	if(IS_POST){
    		$data = I("post.");
    	    $catid = $data['cat_id'];
    	    unset($data['cat_id']);
    	  $cat->where("cat_id=".$catid)->save($data);
          $this->redirect("admin/cat/catelist"); 
    	}
    	if(IS_GET){
    	    $catArr=$cat->find(I("get.cat_id"));
    	    
    	}
    	$this->assign("catinfo",$catArr);
    	$this->assign("cattree",$cat->gettree());
        $this->display();
    }
    public function catedel()
    {
       $catid=I("get.cat_id");
       $cat = D("Cat");
      if($cat->delete($catid)){
        $this->redirect("admin/cat/catelist");
     }
    }
}